<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师后台-不学也通-课程修改</title>
    <link rel="shortcut icon" href="../康笑长结业课.jpg" type="image/x-icon">
    <style>
        .container {
            min-height: 100vh;
        }

        .container .nav {
            height: 100%;
            background-color: #fff;
        }

        .link-secondary {
            text-decoration: none;
        }

        .link-secondary:hover {
            color: #0d6efd !important;
        }
    </style>
</head>

<body>
    <!-- container是bootstrap的居中窄的显示方案 -->
    <div class="container bg-body">
        <div class="row">
            <div class="col-md-2 leftmenu" id="leftmenu">

            </div>
            <div class="col-md-9 kc ms-3">
                <div class="row mt-3 pd-3 border-bottom border-secondary">
                    <div class="col-md-2">编辑课程</div>
                    <div class="col-md-1 offset-md-8">
                        <a class="nav-link link-success" href="javascript:history.go(-1)">返回</a>
                    </div>
                </div>
                <div class="row mt-3">
                    <form>
                        <div class="mb-3 row">
                            <label for="teacher_id" class="col-sm-2 col-form-label">课程编号</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="teacher_id">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="course_name" class="col-sm-2 col-form-label">课程名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="course_name">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="course_url" class="col-sm-2 col-form-label">图片</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="course_url">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="course_department" class="col-sm-2 col-form-label">院系:</label>
                            <div class="col-sm-10">
                                <select class="form-select" aria-label="Default select example" id="course_department">
                                    <option selected>-- 请选择院系 --</option>
                                    <option value="计算机科学与应用">计算机科学与应用</option>
                                    <option value="教育系">教育系</option>
                                    <option value="中文系">中文系</option>
                                    <option value="数学系">数学系</option>
                                    <option value="美术系">美术系</option>
                                    <option value="音乐系">音乐系</option>
                                    <option value="体育系">体育系</option>
                                    <option value="旅游与酒店管理系">旅游与酒店管理系</option>
                                    <option value="机电系">机电系</option>
                                    <option value="幼儿师范部">幼儿师范部</option>
                                </select>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="teacher_name" class="col-sm-2 col-form-label">教师</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="teacher_name">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-outline-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="module" src="../js/main.js"></script>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/common.js"></script>
    <script>
        $(document).ready(function () {
            function getUrlParams(key) {// 获取网址中参数信息"key"中放属性名
                var url = window.location.search.substr(1);
                if (url == '') {
                    return false;
                }
                var paramsArr = url.split('&');
                for (var i = 0; i < paramsArr.length; i++) {
                    var combina = paramsArr[i].split("=");
                    if (combina[0] == key) {
                        return combina[1];
                    }
                }
                return false;
            }

            $.get(`https://unicloud.codecore.cn/ms/getCourse?id=${getUrlParams("id")}`, {}, function (params) {
                console.log(params);
                if (params.errCode == 0) {
                    let data = params.data;
                    let teacher_id = $("#teacher_id").val(data.teacher_id)
                    let course_name = $("#course_name").val(data.course_name)
                    let course_url = $("#course_url").val(data.course_url)
                    let teacher_name = $("#teacher_name").val(data.teacher_name)
                    let course_department = $("#course_department").val(data.course_department)
                
                }
            })
            $(".btn-outline-primary").click(function () {
                let teacher_id = $("#teacher_id").val()
                let course_name = $("#course_name").val()
                let course_url = $("#course_url").val()
                let teacher_name = $("#teacher_name").val()
                let course_department = $("#course_department").val()

                $.post("http://unicloud.codecore.cn/ms/courseUpdate", {
                    id: getUrlParams("id"),
                    teacher_id: teacher_id,
                    course_name: course_name,
                    course_url: course_url,
                    teacher_name: teacher_name,
                    course_department:course_department
                }, function (params) {
                    if (params.errCode == 0) {
                        location.href = "./index.html"
                    } else {
                        alert("编辑失败")
                    }
                })
            })
        })


    </script>
</body>

</html>